﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.Drawing;

namespace Spencen.Mobile.UI.Transforms
{
    public class TranslateTransform : Transform
    {
        public TranslateTransform( Point offset )
        {
            Offset = offset;
        }

        public Point Offset { get; set; }

        public override Point[] TransformedPoints( Point[] points, Point center )
        {
            return TransformedPoints( points, center, Offset );
        }

        public override Point[] TransformedPointsReverse( Point[] transformedPoints, Point center )
        {
            return TransformedPoints( transformedPoints, center, new Point( -Offset.X, -Offset.Y ) );
        }

        private static Point[] TransformedPoints( Point[] points, Point center, Point offset )
        {
            var translatedPoints = new Point[ points.Length ];
            for ( int index = 0; index < points.Length; index++ )
            {
                var point = points[ index ];
                translatedPoints[ index ].X = point.X + offset.X;
                translatedPoints[ index ].Y = point.Y + offset.Y;
            }
            return translatedPoints;
        }
    }
}
